package com.exam.controller;

import com.exam.mapper.PaperMapMapper;
import com.exam.pojo.ChoiceQuestion;
import com.exam.pojo.ComposePaper;
import com.exam.pojo.PaperMap;
import com.exam.service.ChoiceQuestionService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ChoiceQuestionController {
    @Resource
    private ChoiceQuestionService choiceQuestionService;
    @GetMapping("/manage/choice/look/{id}/{pageNum}/{pageSize}")
    public PageInfo<ChoiceQuestion> findPageByPaperId(
            @PathVariable("id") Integer paperId,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return choiceQuestionService.queryPageByPaperId(paperId,pageNum,pageSize);
    }
    @GetMapping("/manage/choice/{id}/{pageNum}/{pageSize}")
    public PageInfo<ChoiceQuestion> findPageByQuestionCreatorId(
            @PathVariable("id") Integer questionCreatorId,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return choiceQuestionService.queryPageByQuestionCreatorId(questionCreatorId,pageNum,pageSize);
    }
    @GetMapping("/manage/choice/{pageNum}/{pageSize}")
    public PageInfo<ChoiceQuestion> findAllPage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return choiceQuestionService.queryAllPage(pageNum,pageSize);
    }
    @PutMapping("/manage/choice/update")
    public int updateById(@RequestBody ChoiceQuestion choiceQuestion){
        return choiceQuestionService.updateById(choiceQuestion);
    }
    @PostMapping("/manage/choice/add")
    public int add(@RequestBody ChoiceQuestion choiceQuestion){
        return choiceQuestionService.add(choiceQuestion);
    }
    @DeleteMapping("/manage/choice/delete/{id}")
    public Boolean deteleById(@PathVariable("id") Integer id){
        try {
            choiceQuestionService.deleteById(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    @GetMapping("/manage/choice/subnum/{id}")
    public List<ComposePaper> findSubNumByQuestionCreatorId(@PathVariable("id") Integer questionCreatorId){
        return choiceQuestionService.querySubNumByQuestionCreatorId(questionCreatorId);
    }
    @GetMapping("/manage/choice/subnum")
    public List<ComposePaper> findSubNum(){
        return choiceQuestionService.querySubNum();
    }

}
